/**
 * Created by user on 16/5/25.
 */

import React, {
    Component,
} from 'react'

import {
    StyleSheet,
    View,
    WebView,
    Dimensions,
    Platform,
    ImageBackground,
    ScrollView,
    Alert,
    // FlatList,
    TouchableOpacity,
    AsyncStorage,
    Text, Image
    //Toast
} from 'react-native';
import Banner from 'react-native-swiper';
import VideoPlayerPage from './Control/Videopage'
import Start from './MainScreen'

import BasePage from './BasePage';
import Video from 'react-native-video'
import CommonStyle from './Component/CommonStyle'
import {Theme, NavigationPage, ListRow, NavigationBar, Label, Button} from 'teaset';
import LoginPage from './LoginPage'


export let screenW = Dimensions.get('window').width;
export let screenH = Dimensions.get('window').height;
const X_WIDTH = 375;
const X_HEIGHT = 812;
import BoundPage from './BoundPage'
import Swiper from 'react-native-swiper';
import MyButton from "./Component/Common/MyButton";
import WebcomePage from './WebcomePage'

var iPX = (Platform.OS === 'ios' && ((screenH === X_HEIGHT && screenW === X_WIDTH) || (screenH === X_WIDTH && screenW === X_HEIGHT))) ? true : false


const screenWidth = Dimensions.get('window').width;
export default class QIDongPage extends BasePage {


    handleMethod(isConnected) {
        console.log('test', (isConnected ? 'online' : 'offline'));
    }

    constructor(props) {

        super(props);
        this._onChangecount = this._onChangecount.bind(this);
        this.player = null

        this.state = {
            isplay: true,
            volume: 1,
            muted: false,

        };

        this.onLoad = this.onLoad.bind(this);
        this.onProgress = this.onProgress.bind(this);
    }

    componentDidMount() {
        // 延迟点
        setTimeout(this.openApp.bind(this), 2000);
        // this.openApp();
    }

    openApp() {


        AsyncStorage.getItem('isFirst', (error, result) => {
                if (result == 'false') {
                    console.log('不是第一次打开');


                    AsyncStorage.getItem('person', (error, result) => {
                        if (error) {
                            // alert('读取失败')
                        } else {
                            console.log(result)
                            let jsonValue = JSON.parse(result);

                            var isloadjs = jsonValue ? jsonValue.islond : 0;

                            if (isloadjs == 1) {

                                this.navigator.resetTo({
                                    view: <Start/>
                                })

                            } else {
                                this.navigator.resetTo({
                                    view: <LoginPage/>
                                })
                            }

                        }
                    })


                } else {
                    console.log('第一次打开');

                    // 存储
                    AsyncStorage.setItem('isFirst', 'false', (error) => {
                        if (error) {
                            alert(error);
                        }
                    });

                    this.navigator.resetTo({
                        view: <WebcomePage/>
                    })

                }


            }
        )

    }

    onLoad() {

    }

    onProgress() {

    }

    onBuffer() {

    }

    onEnd() {

    }

    webOnError(err) {

        //this.refs[WEBVIEW_REF].reload();
    }

    webStartLoad(res) {


    }

    _onChangecount(inputData) {

        this.setState({Replycontent: inputData});
    }

    _saveData() {

    }

    popdalog() {
        Alert.alert('温馨提示', '尚未绑定网关，无法使用场景，请先绑定网关', [{
            text: '取消',
            onPress: () => console.log('Cancel Pressed'),
            style: 'cancel'
        }, {
            text: '去绑定', onPress: () => {
                this.navigator.push({
                    view: <BoundPage/>
                })
            }
        },])

    }


    render() {

        return (

            <View style={{width: screenW, height: screenH, backgroundColor: '#DDFAFE', alignItems: 'center',}}>


                <View style={
                    {
                        height: 100,
                        width: 200,

                        flexDirection: 'row',
                        justifyContent: 'center',

                        alignItems: 'flex-end',
                        bottom: 70,
                        position: 'absolute',
                    }
                }>

                    <Image
                        resizeMode={'stretch'} style={{

                        width: 30,
                        height: 30,

                    }}
                        source={require('./images/qidong.png')}/>
                    <View style={
                        {

                            height: 30,
                            marginLeft: 5,
                            alignItems: 'center',
                            flexDirection: 'column',
                            justifyContent: 'center',
                        }}>

                        <Text
                            style={{
                                fontSize: 11
                            }}
                        >易盈宝典
                        </Text>
                        <Text
                            style={
                                {
                                    fontSize: 6,

                                }
                            }
                        >Yi surplus bible
                        </Text>
                    </View>
                </View>
            </View>

        );
    }
}
var styles = StyleSheet.create({
    container2: {
        flex: 1,
        backgroundColor: '#efefef',
        justifyContent: 'flex-start', flexDirection: 'column',
        ...Platform.select({
            ios: {
                paddingTop: 0
            },
            android: {
                paddingTop: 0
            },
        }),
    },
    webView: {

        height: Dimensions.get('window').height - 64,
        width: Dimensions.get('window').width,
        //backgroundColor:'red',
    },
    webStyle: {

        paddingTop: Platform.OS === 'ios' ? 20 : 0,
    },
    wrapper: {
        height: 200
    },
    slide1: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#9DD6EB'
    },
    slide2: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#97CAE5'
    },
    slide3: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#92BBD9'
    },
    text: {
        color: '#fff',
        fontSize: 30,
        fontWeight: 'bold'
    },
    swiper: {},
    backgroundVideo: {
        width: '100%', marginTop: 0, height: 210
    },
    container: {
        flex: 1,
        marginBottom: iPX ? 34 : 0,
        width: CommonStyle.screenwidth
    },
    headerContainer: {
        width: CommonStyle.screenwidth,
        height: 210,
        alignItems: 'center', justifyContent: 'center'
    },
    scrollTab: {
        flex: 1,
    }
});